package com.gking.centerSystem.controller;


import com.gking.centerSystem.common.Result;
import com.gking.centerSystem.entity.Routes;
import com.gking.centerSystem.service.RoleRoutes.RoleRoutesService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/roleRoutes")
public class RoleRoutesController {

    @Autowired
    private RoleRoutesService roleRoutesService;


    /**
     * 获取角色路由详情
     *
     * @param roleId 角色id
     * @return s
     */
    @RequiresPermissions("CS:manager:get:roleRoutes")
    @GetMapping("/roleRoutesDetail/{roleId}")
    public Result<List<Routes>> getRoleRoutesDetail(@PathVariable String roleId) {
        return roleRoutesService.getRoleRoutesDetail(roleId);
    }

    /**
     * 为角色批量设置路由
     *
     * @param roleId       角色id
     * @param type         类型 （refresh, add, remove）
     * @param routesIdList 权限id 列表
     * @return s
     */
    @RequiresPermissions("CS:manager:set:roleRoutes")
    @PostMapping("/setRoleRoutes/{roleId}")
    public Result<String> setRoleRoutes(@PathVariable String roleId, @RequestParam String type,
                                        @RequestBody List<String> routesIdList) {
        return roleRoutesService.setRoleRoutes(roleId, type, routesIdList);
    }
}
